-module(client_test).
-include("proto_record.hrl").

-export([send/0, pack_unpack_test/0]).

send() ->
  BinMsg = <<"test">>,
  SomeHostInNet = "localhost",
  {ok, Sock} = gen_tcp:connect(SomeHostInNet, 9088,
    [binary, {packet, line}]),
  ok = gen_tcp:send(Sock, BinMsg),
  receive
    {tcp,Socket,String} ->
      io:format("Client received = ~p~n",[String]),
      gen_tcp:close(Socket)
  after 60000 ->
    exit
  end,
  ok = gen_tcp:close(Sock).

pack_unpack_test() ->
  Data = #s2c_test{data = "456789中文",id = 1245},
  {ok, Res} = pack:pack([Data]),
  {ok, [{_MsgId, Res2}|_], _} = unpack:unpack(Res),
  io:format("~n ~w", [Res2]),
  io:format("~n ~w ~w", [Res2#s2c_test.data, Res2#s2c_test.id]),

  ok.